﻿<%@ Control Language="C#" AutoEventWireup="true"  CodeBehind="FlowTrackingInfo.ascx.cs" Inherits="DMS.Web.Common.Controls.FlowTrackingInfo"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="DMS.Base" %>

<table width="100%" id="comment2" cellpadding="0" cellspacing="1" id="tb_5" class="dg_borderstyle detailList trackList" style="display:block;">
    <tr><th class="dg_headerstyle">
            处理步骤
        </th>
        <th class="dg_headerstyle">
            处理意见
        </th>
        <th class="dg_headerstyle">
            处理人
        </th>
        <th class="dg_headerstyle">
            时间
        </th>       
    </tr>
    <% 
        StringBuilder outputString = new StringBuilder();
        string HTML2 = @"<tr class=""{0}"">
                                <td>
                                    {4}
                                </td>
                                <td>
                                {3} 
                                </td>
                                <td>
                                    {1}
                                </td>
                                <td>
                                    {2}
                                </td>                        
                            </tr>";
        const string HTML3 = "</table>";
        string instanceID = Request.QueryString["instanceID"];
        if(string.IsNullOrEmpty(instanceID))
        {
            instanceID = this.InstanceId;
        }
        //TODO
        string sql_end = "";//this.TrackInfoType == null ? " and wType is null " : this.TrackInfoType ;
        //sql_end += this.Params == null ? "" : " and (wFormParams ='" + this.Params + "' or wFormParams is null)";
        int i = 0;
        if (!string.IsNullOrEmpty(instanceID))
        {

            string sql = string.Format(@"SELECT * FROM WF_WorkItems WHERE InstanceID='{0}' and ActivityName!='结束' and finishTime IS NOT NULL " + sql_end + " ORDER by finishTime", instanceID);
            using (IDataReader reader = DBHelper.Instance.ExecuteReader(CommandType.Text, sql))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        string originalUserInfo = reader["ORIGINALPARTNAME"].ToString();
                        if (!string.IsNullOrEmpty(originalUserInfo))
                            originalUserInfo = "（代：" + reader["ORIGINALPARTNAME"].ToString() + " " + reader["ORIGINALPARTDEPTNAME"].ToString() + "）";
                        outputString.Append(string.Format(HTML2, i % 2 == 0 ? "dg_alternatingitemstyle" : "dg_itemstyle",
                            reader["PartName"].ToString() + " " + reader["PartDeptName"].ToString()
                            + originalUserInfo , reader["FinishTime"].ToString(),
                            reader["Opinion"].ToString() + (reader["OpinionDetail"].ToString() == "" ? "" : (reader["Opinion"].ToString()==""?"":"：")) + reader["OpinionDetail"].ToString(), reader["ActivityName"].ToString()
                            ));
                        i++;
                    }
                }
            }
            sql = string.Format(@"SELECT * FROM WF_WorkItems WHERE InstanceID='{0}' and ActivityName!='结束' and finishTime IS NULL " + sql_end + " order by ReceiveTime desc ", instanceID);
            using (IDataReader reader = DBHelper.Instance.ExecuteReader(CommandType.Text, sql))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        string originalUserInfo = reader["ORIGINALPARTNAME"].ToString();
                        if (!string.IsNullOrEmpty(originalUserInfo))
                            originalUserInfo = "（代：" + reader["ORIGINALPARTNAME"].ToString() + " " + reader["ORIGINALPARTDEPTNAME"].ToString() + "）";
                        outputString.Append(string.Format(HTML2, i % 2 == 0 ? "dg_alternatingitemstyle" : "dg_itemstyle",
                            reader["PartName"].ToString() + " " + reader["PartDeptName"].ToString()
                            + originalUserInfo , reader["FinishTime"].ToString(),
                            reader["Opinion"].ToString() + (reader["OpinionDetail"].ToString()==""?"":"：") + reader["OpinionDetail"].ToString(), reader["ActivityName"].ToString()
                            ));
                        i++;
                    }
                }
            }
            sql = string.Format(@"SELECT '' as PartName, '' as PartDeptName,FinishTime,Opinion,ActivityName FROM WF_WorkItems WHERE InstanceID='{0}' and ActivityName='结束' " + sql_end, instanceID);
            using (IDataReader reader = DBHelper.Instance.ExecuteReader(CommandType.Text, sql))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        outputString.Append(string.Format(HTML2, i % 2 == 0 ? "dg_alternatingitemstyle" : "dg_itemstyle",
                            reader["PartName"].ToString() + " " + reader["PartDeptName"].ToString(), reader["FinishTime"].ToString(),
                            "", reader["ActivityName"].ToString()
                            ));
                        i++;
                    }
                }
            }
        }
        
        //非工作流轨迹
        if(!string.IsNullOrEmpty(ExtendStr))
        {
            outputString.Append(ExtendStr);
        }
        
        outputString.Append(HTML3);

        //Response.Write(outputString.ToString());
    %>
    <% Response.Write(outputString.ToString()); %>
</table>
